/* Copyright 2009
 *
 * This program and the accompanying materials
 * are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * Contributors:
 * 	   IBM Corporation - initial API and implementation for JDT/DLTK
 *     Sean W. Quinn - initial adoption for use with PHP from various sources.
 */
package org.eclipse.php.internal.ui.preferences.formatter.profile;

import java.util.Map;

import org.eclipse.dltk.ui.formatter.IProfile;

/**
 * Represents a built-in profile. The state of a built-in profile cannot be
 * changed after instantiation.
 */
public final class BuiltInProfile extends PHPProfile {
	/**
	 *
	 */
	private final int order;

	/**
	 * @return
	 */
	protected int getOrder() {
		return order;
	}

	/**
	 * <p>
	 * Instantiates a new instance of the {@link BuiltInProfile}.
	 * </p>
	 *
	 * @param ID the ID of this <code>Profile</code>.
	 * @param name the name of this <code>Profile</code>.
	 * @param formatterSettings the settings for this <code>Profile</code>.
	 * @param order the order of this <code>Profile</code>.
	 * @param currentVersion the current version of this <code>Profile</code>.
	 * @param profileKind the kind of this <code>Profile</code>.
	 */
	public BuiltInProfile(final String id, final String name, final Map formatterSettings, final int order,
			final int currentVersion, final String profileKind) {
		super(id, name, formatterSettings, currentVersion, profileKind);
		this.order = order;
	}

	/**
	 *
	 */
	@Override
	public PHPProfile rename(final String name, final PHPProfileManager manager) {
		final String trimmed = name.trim();
		final CustomProfile newProfile = new CustomProfile(trimmed, getSettings(), getVersion(), getKind());
		manager.addProfile(newProfile);
		return newProfile;
	}

	/**
	 * <p>
	 * Overrides the {@link PHPProfile#setSettings(Map)} method, to prevent a
	 * built-in profile from being over written by modifications.
	 * </p>
	 */
	@Override
	public void setSettings(final Map settings) {}

	/**
	 * @return <tt>false</tt>, {@link BuiltInProfile}'s cannot be saved.
	 */
	@Override
	public boolean isProfileToSave() {
		return false;
	}

	/**
	 * @return <tt>true</tt> this profile is a {@link BuiltInProfile}.
	 */
	@Override
	public boolean isBuiltInProfile() {
		return true;
	}

	/**
	 *
	 */
	public final int compareTo(final IProfile profile) {
		if (profile instanceof BuiltInProfile) {
			return order - ((BuiltInProfile) profile).getOrder();
		}
		return -1;
	}
}
